package work.jame.blog.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import work.jame.blog.framework.result.Result;
import work.jame.blog.pojo.UserConfiguration;
import work.jame.blog.service.UserConfigurationService;

import java.util.Objects;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Jame
 * @since 2023-05-15
 */
@Api(tags = "用户配置")
@RestController
@RequestMapping("/userConfiguration")
public class UserConfigurationController {

    @Autowired
    private UserConfigurationService userConfigurationService;

    @ApiOperation("获取当前用户配置项")
    @GetMapping("/get")
    public Result<?> get() {
        UserConfiguration userConfiguration = userConfigurationService.getCurrentLoginUserConfiguration();
        if(Objects.isNull(userConfiguration)){
            return Result.fail();
        }
        return Result.succeed(userConfiguration);
    }



    @ApiOperation("修改用户配置项")
    @PostMapping("/update")
    public Result<?> update(@RequestBody UserConfiguration userConfiguration){
        if (userConfigurationService.updateUserConfiguration(userConfiguration)) {
            return Result.succeed();
        }
        return Result.fail();
    }


}
